<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.SQLException" %><%--
  Created by IntelliJ IDEA.
  User: 张勤晓
  Date: 2023/10/27
  Time: 20:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>添加品牌</title>

</head>
<body>
<h3>添加品牌</h3>
<%
    Class.forName("com.mysql.jdbc.Driver");

    String url = "jdbc:mysql:///db1?useSSL=false";
    String username = "root";
    String password = "1234";

    Connection conn = DriverManager.getConnection(url, username, password);

    String sql = "insert into tb_brand(brand_name,company_name,ordered,description,status) values(?,?,?,?,?)";


%>
<form action="" method="get">
    品牌名称：<input type="text" name="brandName"><br>
    企业名称：<input type="text" name="companyName"><br>
    排序：<input name="ordered"><br>
    描述信息：<textarea rows="5" cols="40" name="description"></textarea><br>
    状态：
    <input type="radio" name="status" value="0">禁用
    <input type="radio" name="status" value="1">启用<br>

    <input type="submit" value="提交">
</form>

<%
    PreparedStatement pstmt = conn.prepareStatement(sql);
    try {
        if (request.getParameter("brandName") != null) {
            pstmt.setString(1, request.getParameter("brandName"));
            pstmt.setString(2, request.getParameter("companyName"));
            pstmt.setString(3, request.getParameter("ordered"));
            pstmt.setString(4, request.getParameter("description"));
            pstmt.setString(5, request.getParameter("status"));
            int count = pstmt.executeUpdate();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }


%>
<%
    //释放资源

    pstmt.close();
    conn.close();
%>

</body>
</html>